package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:归还书籍
 * User: 86184
 * Date: 2023-02-18
 * Time: 15:21
 */
public class ReturnOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("请输入你要归还的书籍得到书名!");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();

        int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getPos(i);
            if (name.equals(book.getName())) {
                if(!book.isBorrowed()){
                    System.out.println("该书未被借出");
                    return;
                }else {
                    book.setBorrowed(false);
                    System.out.println("归还成功");
                    return;
                }
            }
        }
        System.out.println("没有找到你要归还的书");
    }
}
